<%-- 
    Document   : calendrierSelect
    Created on : 18 avr. 2013, 15:28:24
    Author     : ali
--%>

<%@page import="EDT.api.API"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page
	import="com.sun.corba.se.impl.encoding.CodeSetConversion.CTBConverter"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Emploi du temps</title>
<link rel="stylesheet" href="calendrier.css" />
<style type="text/css">
dl.defs {
	margin: 10px 0 10px 40px;
}

dl.defs dt {
	font-weight: bold;
	line-height: 20px;
	margin: 10px 0 0 0;
}

dl.defs dd {
	margin: -20px 0 10px 160px;
	padding-bottom: 10px;
	border-bottom: solid 1px #eee;
}

.wrapper {
	background-color: #ffffff;
	width: 800px;
	border: solid 1px #eeeeee;
	padding: 20px;
	margin: 0 auto;
}

#tabs {
	margin: 20px -20px;
	border: none;
}

#tabs,#ui-datepicker-div,.ui-datepicker {
	font-size: 85%;
}

.clear {
	clear: both;
}
</style>
<link rel="stylesheet" media="all" type="text/css"
	href="http://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" media="all" type="text/css"
	href="jquery-ui-timepicker-addon.css" />

<script type="text/javascript"
	src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script type="text/javascript"
	src="http://code.jquery.com/ui/1.10.0/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="jquery-ui-sliderAccess.js"></script>
<script type="text/javascript">
	$(function() {
		$('#tabs').tabs();

		$('.example-container > pre').each(function(i) {
			eval($(this).text());
		});
	});
</script>


<script language="JavaScript">
	var compteur = 0;

	function Supprimer(id) {

		//if(document.getElementById(id).childNodes[1].firstChild.firstChild.checked == false){
		if (document.getElementById(id).childNodes[1].checked == false) {

			document.getElementById(id).childNodes[1].checked = true;
			compteur++;
		} else {
			document.getElementById(id).childNodes[1].checked = false;
			compteur--;
		}

	}

	function compt(id) {
		if (document.getElementById(id).childNodes[1].checked == true) {
			compteur++;
		} else {
			compteur--;
		}
	}

	function suppresion() {
		if (compteur > 0) {

			if (confirm("Voulez vous supprimer " + compteur + " créneau(x) ?")) {
				document.getElementById("suppr").submit();
			} else {
			}

		} else {
			alert("Vous devez cochez la case d'un créneau à supprimer !");
		}
	}

	function modifier() {

		var type = document.getElementById("typeModifSelect").value;
		if (compteur > 0 && type != "") {

			if (confirm("Voulez vous modifier " + compteur + " créneau(x) ?")) {
				document.getElementById("modif").submit();
			} else {
			}

		} else {
			var error = "";
			if (type == "")
				error += "Vous devez choisir le type de modification à faire !\n";
			if (compteur < 1)
				error += "Vous devez cochez la case d'un créneau à modifier !";

			alert(error);
		}
	}

	function selection(crs, checkbox) {
		if (checkbox.checked == true)
			for ( var i in crs) {
				if (document.getElementById(crs[i]).childNodes[1].checked != true)
					compteur++;
				document.getElementById(crs[i]).childNodes[1].checked = true;

			}
		else
			for ( var i in crs) {
				if (document.getElementById(crs[i]).childNodes[1].checked == true)
					compteur--;
				document.getElementById(crs[i]).childNodes[1].checked = false;

			}
	}

	$(document).ready(function() {
		$('#hdebut').timepicker({

			hourMin : 8,
			hourMax : 19,
			addSliderAccess : true,
			sliderAccessArgs : {
				touchonly : false
			},

			constrainInput : true

		}

		);

		$('#hfin').timepicker({

			hourMin : 8,
			hourMax : 20,
			addSliderAccess : true,
			sliderAccessArgs : {
				touchonly : false
			},

			constrainInput : true

		}

		);

		$('#timeDecalage').timepicker({
			hourMax : 12,
			addSliderAccess : true,
			sliderAccessArgs : {
				touchonly : false
			},
			constrainInput : true
		}

		);

	});
</script>

<script language="JavaScript">
	var disabledDays;
	$(document).ready(function() {

		disabledDays = JourF();
	});

	$(document).ready(
			function() {
				$('#jour').datepicker(
						{
							dateFormat : "dd-mm-yy",
							minDate : new Date(document
									.getElementsByName('anneeMin')[0].value),
							maxDate : new Date(parseInt(document
									.getElementsByName('annee')[0].value) + 1,
									07, 31, 17, 59),
							addSliderAccess : true,
							sliderAccessArgs : {
								touchonly : false
							},
							constrainInput : true,
							beforeShowDay : noWeekendsOrHolidays
						}

				);

			});

	function nationalDays(date) {
		var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();

		for (i = 0; i < disabledDays.length; i++) {
			if ($.inArray((m + 1) + '-' + d + '-' + y, disabledDays) != -1 /* || new Date() > date */) {
				return [ false ];
			}
		}

		return [ true ];
	}

	function noWeekendsOrHolidays(date) {
		return nationalDays(date);
	}

	function JourF() {

		var resulta = document.getElementsByName('jourf')[0].value;

		var tab = resulta.split(",");

		return tab;
	}

	function active(val) {
		//alert(val.value);
		lesElements = new Array('salle', 'interv', 'visib', 'hdebut', 'hfin',
				'duree', 'jour', 'timeDecal');
		document.getElementById("typeModifSelect").value = val.value;

		var container = document.getElementById(val.value);
		for ( var s in lesElements) {
			if (lesElements[s] == val.value) {
				container.style.visibility = 'visible';
			} else {
				document.getElementById(lesElements[s]).style.visibility = 'hidden';
			}
		}
		/*
		for ( var i in crs){
		        if(document.getElementById(crs[i]).childNodes[1].checked != true)compteur++;
		        document.getElementById(crs[i]).childNodes[1].checked = true;
		        
		    }*/

	}
</script>

</head>
<body>

	<!--<h1>Calendrier : </h1>-->

	<%
		String c = "";

		if (request.getAttribute("msg") != null) {
			c += "<br/><pre> " + request.getAttribute("msg")
					+ "</label></pre><br/>";
		}

		if (request.getAttribute("calendrier") != null
				&& request.getAttribute("annee") != null) {
			c += (String) request.getAttribute("calendrier");

			c += "<input type='hidden' name='key' value='"
					+ (String) session.getAttribute("key") + "'/>";

			int annee = (Integer) request.getAttribute("annee");
			Calendar cal1 = Calendar.getInstance();
			Calendar cal2 = Calendar.getInstance();
			Date dateCourante = new Date();
			cal1.setTime(dateCourante);
			cal2.set(annee, 9, 1);
			DateFormat dateFormat = new SimpleDateFormat("yyyy,MM,dd");

			/*  if(cal1.after(cal2))
			 c += "<input type='hidden' name='anneeMin' value='"+dateFormat.format(cal1.getTime())+"'/>";
			 else */
			c += "<input type='hidden' name='anneeMin' value='" + annee
					+ ",09,01'/>";

			c += "<input type='hidden' name='annee' value='" + annee
					+ "'/>";

			c += "<input type='hidden' name='typeModifSelect' id='typeModifSelect'/>";

			String jourFerie = API.getJourferie(annee);
			c += "<input type='hidden' name='jourf' value='" + jourFerie
					+ "'/>";

			c += "<input type='hidden' name='formation' value='"
					+ request.getAttribute("formation") + "'/>";
			c += "<input type='hidden' name='promo' value='"
					+ request.getAttribute("promo") + "'/>";
			c += "<input type='hidden' name='periode' value='"
					+ request.getAttribute("periode") + "'/>";
			c += "<input type='hidden' name='nbrPeriode' value='"
					+ request.getAttribute("nbrPeriode") + "'/>";
			c += "<input type='hidden' name='grp' value='"
					+ request.getAttribute("grp") + "'/>";

			c += "</form>";

			out.println(c);

		}

		//out.println("Wow");
	%>


</body>
</html>
